package edu.bw.service.impl;

import edu.bw.dao.DeptDao;
import edu.bw.dao.impl.DeptDaoImpl;
import edu.bw.dto.SelectDeptByConditionForm;
import edu.bw.dto.UpdateDeptForm;
import edu.bw.pojo.Dept;
import edu.bw.service.DeptService;
import edu.bw.utils.PageUtils;

import java.util.List;
import java.util.Map;

public class DeptServiceImpl implements DeptService {
    DeptDao deptDao=new DeptDaoImpl();
    @Override
    public PageUtils selectDeptByCondition(SelectDeptByConditionForm selectCondition) {
        //根据条件查询数据
        List<Map<String,Object>> list= deptDao.selectDeptByCondition(selectCondition);

        //根据条件查询出总条数
        Long count=deptDao.selectDeptByConditionCount(selectCondition);

        int beginIndex=(selectCondition.getPage()-1)*selectCondition.getLength();

        return new PageUtils(list,count,beginIndex,selectCondition.getLength());
    }

    @Override
    public int insert(Dept dept) {
        return  deptDao.inset(dept);
    }

    @Override
    public List<Map<String, Object>> selectById(Integer id) {
        return deptDao.selectById(id);
    }

    @Override
    public Integer updateDept(UpdateDeptForm updateDeptForm) {

        return deptDao.updateDept(updateDeptForm);
    }

    @Override
    public int deleteDeptByIds(List<Integer> ids) {
        int rows=0;
        if (deptDao.selectCanDelete(ids)){
            rows=deptDao.deleteDeptByIds(ids);
        }
        return rows;

    }

    @Override
    public List<Map<String, Object>> selectAllDept() {
        return deptDao.selectAllDept();
    }
}
